<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
        <title>我的提问/我的分享-品购网</title>
        <link href="__PUBLIC__/css/hangye.css" rel="stylesheet" type="text/css" />
        <link href="__PUBLIC__/css/person.css" rel="stylesheet" type="text/css" />
        <link href="__PUBLIC__/css/comm.css" rel="stylesheet" type="text/css" />
		<link href="__PUBLIC__/css/panel.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="__PUBLIC__/js/jquery.js"></script>
    </head>
    <body>
	   <div class="containner">
        <include file="Index:header"/>
        <!--导航结束--> 
        <div id="myshare" style="position:absolute;top:0px;margin:auto;z-index:299"></div>
        <div class="body-center">
<!--            <div class="path">
				首页 >> 个人页面 >> 我的提问/我的分享
            </div>-->
            <div class="w_tithead"> <strong>您当前的位置是： </strong><a href="__APP__">品购网首页</a><a  href="#">个人信息</a>我的提问/我的分享</div>
            <div class="person_title">我的收藏</div>
            <div class="contents">
                <div class="menu">
                    <include file="user_menu"/>

                </div>
                <div class="content">

                    <div class="tab" id="tab" style="width:95%">
                        <ul  id="tab">
                            <li class="on" tabcontent="myquertion">我的提问</li>
                            <li tabcontent="myshare">我的分享</li>
                            <li tabcontent="myquestionShare">我的回答的分享</li>
                        </ul>
                        <div class="btns" style="float:right">
                            <a id="search" href="__APP__/Question/showAdd" hidefocus class="bluebtn caina" stye="text-decoration:none">发表提问</a>
                        </div>
                        <!--        <span style="float:right">排序按：<select id="paixu" style="display:none">
                                        <option>时间</option>
                                        <option>分数</option>
                                        <option>浏览数目</option>
                                        <option>采纳数目</option>
                                    </select><select id="paixutiwen">
                                        <option>时间</option>
                                        <option>收到的分享数目</option>
                                    </select></span>-->
                    </div>
                    <div id="quertion">

                    </div>

                </div>
            </div>
        </div>
	<include file="Index:bottom" />
    <!--页尾部分-->	
	</div>
    </body>
</html>
<script>
    $(function(){
        var url = "__APP__";
        bindtab(url);
        bindPaixu(url);
        loadtablelsit(url+"/Home/User/myQuestion");
        bindtr();
    });
</script>
<script>
    function show_my_share(condition){
        $.post(
        "__APP__/User/myShare/",
        {p:condition},
        function(data){
            $("#quertion").html(data);
            bindtr();
        }
    )
    }
    function show_my_question(condition){
        $.post(
        "__APP__/User/myQuestion/",
        {p:condition},
        function(data){
            $("#quertion").html(data);
            bindtr();
        }
    )
    }
    function show_my_answerQuestion(condition){
        $.post(
        "__APP__/User/myAnswerQuestion/",
        {p:condition},
        function(data){
            $("#quertion").html(data);
            bindtr();
        }
    )
    }
    function changeSearch(method){
        var url ="";
        var text="";
        if(method=="myquestion"){
            url ="__APP__/Question/showAdd";
            text="发表提问";
        } 
        else{
            url="__APP__/Share/showAdd";
            text="发表分享";
        }
        $("#search").attr("href",url);
        $("#search").text(text);

    }



    function bindtab(url){
        $("#tab li").click(function(){
            var $li = $(this);
            var $sli = $li.siblings();
            var c = $li.attr("tabcontent");
            var sc = $sli.attr("tabcontent");

            if(c=="myquertion"){
                $("#paixutiwen").css("display","");
                $("#paixu").css("display","none");
                loadtablelsit(url+"/Home/User/myQuestion");
                changeSearch("myquestion");
            }
            else if(c=="myquestionShare"){
                $("#paixutiwen").css("display","");
                $("#paixu").css("display","none");
                loadtablelsit(url+"/Home/User/myAnswerQuestion");
               
            }else{
                $("#paixutiwen").css("display","none");
                $("#paixu").css("display","");
                loadtablelsit(url+"/Home/User/myShare");
                changeSearch("myshare");
            }

            $li.addClass("on");
            $sli.removeClass("on");
            $("#"+sc).css("display","none");
            $("#"+c).css("display","block");
        });
    }

    function loadtablelsit(url,param){
        $("#quertion").load(url,param,function(){
            bindtr();
        })
    }
    function bindtr(){
        var trs = $("#quertion tr");
        for (var i = 0; i < trs.length; i++) {
            var $tr = $(trs[i]);
            $tr.find("td:eq(1)").click(function(){
                alert("嘘~我在睡觉……");
            });
            //绑定更多
            $tr.find("td:last").click(function(){
                var $td = $(this);
                if($td.children("div:first").hasClass("bodermore")){
                    clearmenuitem();
                    return;
                }


                var tabs = $("#tab li");
                for(var i=0;i<tabs.length;i++){
                    var $li = $(tabs[i]);
                    if($li.hasClass("on")){
                        var content = $li.attr("tabcontent");
                    }
                }
                if(content=="myquertion"){
                    newmoreMenu($td);
                }else{
                    newmoreMenu($td,true);
                }
                bindmenuitem();

            })
        }
    }

    function bindmenuitem(){
        $("#moremenu ul li a").click(function(e){
            e.stopPropagation();
            e.preventDefault();
            var $li = $(this);
            var method = $li.attr("method");
            if(method=="del"){
                deltr($li);
            }if(method=="top"){
                zhiding($li);
            }if(method=="buchongshare"){
                addshare($li);
            }
            clearmenuitem();
        });
    }

    function clearmenuitem(){
        var $mm = $("#moremenu");
        $mm.prev().removeClass("bodermore");
        if($mm.get(0)){
            $mm.find("ul li a").unbind();
            $mm.parent().get(0).removeChild($mm.get(0));
        }

    }


    function newmoreMenu($td,flag){
        clearmenuitem();
        $td.children("div:first").addClass("bodermore");
        var str =[];
        str[0]='<div id="moremenu" class="menumore">';
        str[1]='<ul>';
        str[2]='<li><a method="del" href="#">删除</a></li>';
        str[3]='<li><a method="top" href="#">推荐置顶</a></li>';
        str[4]='</ul>';
        str[5]='</div>';
        if(flag){
            str.splice(4,0,'<li><a method="buchongshare" href="#">补充分享</a></li>');
        }
        var menu = str.join("");

        $td.append(menu);

    }


    //删除
    function deltr($a){
       
        var trs = $a.parents("tr");
        var tr = trs[0];
        var value = tr.id;
        value = value.split('_');
        var url = "__APP__/Home/share/del/";
        if(value[0]=='question'){
            url = "__APP__/Home/question/del/";
        }
        $.get(
        url,
        {id:value[1]},
        function(data){
            if(data == 1){
                var table = tr.parentNode;
                table.removeChild(tr);
            }
            else{
                alert('操作失败');
            }
        }
    );
	
    }

    function zhiding($a){
        var trs = $a.parents("tr");
        var tr = trs[0];
        var value = tr.id;
        value = value.split('_');
        var url = "__APP__/Home/share/top/";
        if(value[0]=='question'){
            url = "__APP__/Home/question/top/";
        }
        $.get(
        url,
        {id:value[1]},
        function(data){
            if(data == 1){
                window.location.reload();
                return;
            }
            else{
                alert('操作失败');
            }
        }
    );
    }



    function addshare($a){
        var trs = $a.parents("tr");
        var tr = trs[0];
        var value = tr.id;
        value = value.split('_');
        
        var url = "__APP__/Home/share/showAdded/id/"+value[1];
        window.location.href=url;
    }




    //绑定下拉框排序
    function bindPaixu(){
        $("#paixu").change(function(){
            reloadtalbe();
        });
    }

    function reloadtalbe(param){
        var lis = $("#tab li");
        for(var i=0;i<lis.length;i++){
            var $li = $(lis[i]);
            if($li.hasClass("on")){
                var content = $li.attr("tabcontent");
                if(content=="myquertion"){
                    loadtablelsit(url+"/Home/User/myQuestion",param);
                } else if(c=="myquestionShare"){
                    
                    loadtablelsit(url+"/Home/User/myAnswerQuestion",param);
                   
                }else{
                    loadtablelsit(url+"/Home/User/myShare",param);
                }
            }
        }
    }

</script>

